package com.jt9003.controller;

import com.jt9003.pojo.Drugs;
import com.jt9003.service.QueryStockService;
import com.jt9003.utils.PageUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stock")
public class QueryStockController {

    @Resource
    private QueryStockService queryStockService;

    //库存查询页面 分页模糊查询
    @RequestMapping("query")
    @ResponseBody
    public Object queryStock (@RequestParam(value="drType",required=false) Integer drType,
                              @RequestParam(value="drName",required=false)  String drName ,
                              @RequestParam(value="currPage",required=false,defaultValue = "1")  Integer currPage,
                              @RequestParam(value="pageSize",required=false,defaultValue = "5")  Integer pageSize){
        Map map =new HashMap();
        Map param =new HashMap();
        int start = PageUtils.getStart(currPage,pageSize);
        param.put("drType",drType);
        param.put("drName",drName);
        param.put("start",start);
        param.put("pageSize",pageSize);

        try {
            List<Drugs> list = queryStockService.queryStock(param);
            map.put("result",list);
            map.put("success",true);
            map.put("message","查询成功");
        }catch (Exception e){
            e.printStackTrace();
            map.put("success", false);
            map.put("message", "查询失败");
        }
        return map;
    }
}
